<?php
namespace app\main\controller;

use app\main\model\Language;

class LanguageController extends BaseController 
{
    protected $model;
    protected function initialize()
    {
        $this->model = new Language();
    }

    public function indexAction() 
    {
        $items = $this->model->getAll();
        $this->render('view/module/index', ['items'=>$items]);
    }

    public function addAction() 
    {
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->insert($_POST);
            header('Location: /main/language/index'); exit;
        }
        $this->render('view/module/form');
    }

    public function editAction($id) 
    {
        $itemData = $this->model->get($id);
        if($_SERVER['REQUEST_METHOD']==='POST') {
            $this->model->update($id, $_POST);
            header('Location: /main/language/index'); exit;
        }
        $this->render('view/module/form', ['item'=>$itemData]);
    }
    
    public function deleteAction($id) 
    {
        $this->model->delete($id);
        header('Location: /main/language/index'); exit;
    }
}
